<!DOCTYPE html>





<html lang="zh-CN">
<head>
  <!-- hexo-inject:begin --><!-- hexo-inject:end --><meta charset="UTF-8">
<meta name="viewport" content="width=device-width, initial-scale=1, maximum-scale=2">
<meta name="theme-color" content="#222">
<meta name="generator" content="Hexo 4.2.1">
  <link rel="apple-touch-icon" sizes="180x180" href="/sunpages/images/apple-touch-icon-next.png?v=7.4.0">
  <link rel="icon" type="image/png" sizes="32x32" href="/sunpages/images/favicon-32x32-next.png?v=7.4.0">
  <link rel="icon" type="image/png" sizes="16x16" href="/sunpages/images/favicon-16x16-next.png?v=7.4.0">
  <link rel="mask-icon" href="/sunpages/images/logo.svg?v=7.4.0" color="#222">

<link rel="stylesheet" href="/sunpages/css/main.css?v=7.4.0">


<link rel="stylesheet" href="/sunpages/lib/font-awesome/css/font-awesome.min.css?v=4.7.0">


<script id="hexo-configurations">
  var NexT = window.NexT || {};
  var CONFIG = {
    root: '/sunpages/',
    scheme: 'Pisces',
    version: '7.4.0',
    exturl: false,
    sidebar: {"position":"left","display":"post","offset":12,"onmobile":false},
    copycode: {"enable":true,"show_result":false,"style":null},
    back2top: {"enable":true,"sidebar":false,"scrollpercent":true},
    bookmark: {"enable":false,"color":"#222","save":"auto"},
    fancybox: false,
    mediumzoom: false,
    lazyload: false,
    pangu: false,
    algolia: {
      appID: '',
      apiKey: '',
      indexName: '',
      hits: {"per_page":10},
      labels: {"input_placeholder":"Search for Posts","hits_empty":"We didn't find any results for the search: ${query}","hits_stats":"${hits} results found in ${time} ms"}
    },
    localsearch: {"enable":true,"trigger":"auto","top_n_per_article":1,"unescape":false,"preload":false},
    path: 'search.xml',
    motion: {"enable":true,"async":false,"transition":{"post_block":"fadeIn","post_header":"slideDownIn","post_body":"slideDownIn","coll_header":"slideLeftIn","sidebar":"slideUpIn"}},
    translation: {
      copy_button: '复制',
      copy_success: '复制成功',
      copy_failure: '复制失败'
    },
    sidebarPadding: 40
  };
</script>

  <meta name="description" content="实验二实验报告 孙汉武    16281047    安全1601">
<meta property="og:type" content="article">
<meta property="og:title" content="进程实验">
<meta property="og:url" content="https://yuandaima1.gitee.io/sunpages/2019/03/11/lab2/index.html">
<meta property="og:site_name" content="SunPages">
<meta property="og:description" content="实验二实验报告 孙汉武    16281047    安全1601">
<meta property="og:locale" content="zh_CN">
<meta property="og:image" content="http://ipic-picgo.oss-cn-beijing.aliyuncs.com/2019-04-29-171938.jpg">
<meta property="og:image" content="http://ipic-picgo.oss-cn-beijing.aliyuncs.com/2019-04-29-171945.jpg">
<meta property="og:image" content="http://ipic-picgo.oss-cn-beijing.aliyuncs.com/2019-04-29-171948.jpg">
<meta property="og:image" content="http://ipic-picgo.oss-cn-beijing.aliyuncs.com/2019-04-29-171955.jpg">
<meta property="og:image" content="http://ipic-picgo.oss-cn-beijing.aliyuncs.com/2019-04-29-171958.jpg">
<meta property="og:image" content="http://ipic-picgo.oss-cn-beijing.aliyuncs.com/2019-04-29-172002.jpg">
<meta property="og:image" content="https://ws2.sinaimg.cn/large/006tKfTcly1g1a82h4avqj31370u0436.jpg">
<meta property="og:image" content="http://ipic-picgo.oss-cn-beijing.aliyuncs.com/2019-04-29-172008.jpg">
<meta property="og:image" content="http://ipic-picgo.oss-cn-beijing.aliyuncs.com/2019-04-29-172011.jpg">
<meta property="og:image" content="http://ipic-picgo.oss-cn-beijing.aliyuncs.com/2019-04-29-172015.jpg">
<meta property="og:image" content="http://ipic-picgo.oss-cn-beijing.aliyuncs.com/2019-04-29-172020.jpg">
<meta property="og:image" content="http://ipic-picgo.oss-cn-beijing.aliyuncs.com/2019-04-29-172027.jpg">
<meta property="og:image" content="http://ipic-picgo.oss-cn-beijing.aliyuncs.com/2019-04-29-172032.jpg">
<meta property="og:image" content="http://ipic-picgo.oss-cn-beijing.aliyuncs.com/2019-04-29-172037.jpg">
<meta property="og:image" content="https://ws4.sinaimg.cn/large/006tKfTcly1g1a83mqnwoj30uk0u0gr4.jpg">
<meta property="og:image" content="http://ipic-picgo.oss-cn-beijing.aliyuncs.com/2019-04-29-172042.jpg">
<meta property="og:image" content="http://ipic-picgo.oss-cn-beijing.aliyuncs.com/2019-04-29-172048.jpg">
<meta property="og:image" content="http://ipic-picgo.oss-cn-beijing.aliyuncs.com/2019-04-29-172052.jpg">
<meta property="og:image" content="http://ipic-picgo.oss-cn-beijing.aliyuncs.com/2019-04-29-172056.jpg">
<meta property="og:image" content="http://ipic-picgo.oss-cn-beijing.aliyuncs.com/2019-04-29-172100.jpg">
<meta property="og:image" content="http://ipic-picgo.oss-cn-beijing.aliyuncs.com/2019-04-29-172113.jpg">
<meta property="og:image" content="http://ipic-picgo.oss-cn-beijing.aliyuncs.com/2019-04-29-172117.jpg">
<meta property="og:image" content="http://ipic-picgo.oss-cn-beijing.aliyuncs.com/2019-04-29-172121.jpg">
<meta property="og:image" content="http://ipic-picgo.oss-cn-beijing.aliyuncs.com/2019-04-29-172123.jpg">
<meta property="og:image" content="http://ipic-picgo.oss-cn-beijing.aliyuncs.com/2019-04-29-172128.jpg">
<meta property="og:image" content="http://ipic-picgo.oss-cn-beijing.aliyuncs.com/2019-04-29-172131.jpg">
<meta property="og:image" content="http://ipic-picgo.oss-cn-beijing.aliyuncs.com/2019-04-29-172138.jpg">
<meta property="og:image" content="http://ipic-picgo.oss-cn-beijing.aliyuncs.com/2019-04-29-172141.jpg">
<meta property="og:image" content="https://ws1.sinaimg.cn/large/006tKfTcly1g1a85bo9v3j316u06y3z9.jpg">
<meta property="og:image" content="http://ipic-picgo.oss-cn-beijing.aliyuncs.com/2019-04-29-172147.jpg">
<meta property="og:image" content="http://ipic-picgo.oss-cn-beijing.aliyuncs.com/2019-04-29-172148.jpg">
<meta property="og:image" content="http://ipic-picgo.oss-cn-beijing.aliyuncs.com/2019-04-29-172155.jpg">
<meta property="og:image" content="http://ipic-picgo.oss-cn-beijing.aliyuncs.com/2019-04-29-172151.jpg">
<meta property="og:image" content="http://ipic-picgo.oss-cn-beijing.aliyuncs.com/2019-04-29-172158.jpg">
<meta property="og:image" content="https://ws1.sinaimg.cn/large/006tKfTcly1g1a85yjcijj313e0lmdi6.jpg">
<meta property="og:image" content="http://ipic-picgo.oss-cn-beijing.aliyuncs.com/2019-04-29-172202.jpg">
<meta property="og:image" content="http://ipic-picgo.oss-cn-beijing.aliyuncs.com/2019-04-29-172205.jpg">
<meta property="og:image" content="http://ipic-picgo.oss-cn-beijing.aliyuncs.com/2019-04-29-172208.jpg">
<meta property="og:image" content="http://ipic-picgo.oss-cn-beijing.aliyuncs.com/2019-04-29-172212.jpg">
<meta property="og:image" content="https://ws4.sinaimg.cn/large/006tKfTcly1g1a86kbwu9j313g0patbj.jpg">
<meta property="og:image" content="http://ipic-picgo.oss-cn-beijing.aliyuncs.com/2019-04-29-172216.jpg">
<meta property="og:image" content="http://ipic-picgo.oss-cn-beijing.aliyuncs.com/2019-04-29-172220.jpg">
<meta property="og:image" content="http://ipic-picgo.oss-cn-beijing.aliyuncs.com/2019-04-29-172223.jpg">
<meta property="og:image" content="http://ipic-picgo.oss-cn-beijing.aliyuncs.com/2019-04-29-172226.jpg">
<meta property="article:published_time" content="2019-03-11T12:10:33.000Z">
<meta property="article:modified_time" content="2019-09-12T09:35:49.000Z">
<meta property="article:author" content="sunhanwu">
<meta property="article:tag" content="操作系统">
<meta name="twitter:card" content="summary">
<meta name="twitter:image" content="http://ipic-picgo.oss-cn-beijing.aliyuncs.com/2019-04-29-171938.jpg">
  <link rel="canonical" href="https://yuandaima1.gitee.io/sunpages/2019/03/11/lab2/">


<script id="page-configurations">
  // https://hexo.io/docs/variables.html
  CONFIG.page = {
    sidebar: "",
    isHome: false,
    isPost: true,
    isPage: false,
    isArchive: false
  };
</script>

  <title>进程实验 | SunPages</title>
  








  <noscript>
  <style>
  .use-motion .brand,
  .use-motion .menu-item,
  .sidebar-inner,
  .use-motion .post-block,
  .use-motion .pagination,
  .use-motion .comments,
  .use-motion .post-header,
  .use-motion .post-body,
  .use-motion .collection-header { opacity: initial; }

  .use-motion .logo,
  .use-motion .site-title,
  .use-motion .site-subtitle {
    opacity: initial;
    top: initial;
  }

  .use-motion .logo-line-before i { left: initial; }
  .use-motion .logo-line-after i { right: initial; }
  </style>
</noscript><!-- hexo-inject:begin --><!-- hexo-inject:end -->

</head>

<body itemscope itemtype="http://schema.org/WebPage" lang="zh-CN">
  <!-- hexo-inject:begin --><!-- hexo-inject:end --><div class="container use-motion">
    <div class="headband"></div>

    <header id="header" class="header" itemscope itemtype="http://schema.org/WPHeader">
      <div class="header-inner"><div class="site-brand-container">
  <div class="site-meta">

    <div>
      <a href="/sunpages/" class="brand" rel="start">
        <span class="logo-line-before"><i></i></span>
        <span class="site-title">SunPages</span>
        <span class="logo-line-after"><i></i></span>
      </a>
    </div>
        <h1 class="site-subtitle" itemprop="description">屁话少说,放码过来！</h1>
      
  </div>

  <div class="site-nav-toggle">
    <button aria-label="切换导航栏">
      <span class="btn-bar"></span>
      <span class="btn-bar"></span>
      <span class="btn-bar"></span>
    </button>
  </div>
</div>


<nav class="site-nav">
  
  <ul id="menu" class="menu">
      
      
      
        
        <li class="menu-item menu-item-home">
      
    

    <a href="/sunpages/" rel="section"><i class="menu-item-icon fa fa-fw fa-home"></i> <br>首页</a>

  </li>
      
      
      
        
        <li class="menu-item menu-item-about">
      
    

    <a href="/sunpages/about/" rel="section"><i class="menu-item-icon fa fa-fw fa-user"></i> <br>关于</a>

  </li>
      
      
      
        
        <li class="menu-item menu-item-tags">
      
    

    <a href="/sunpages/tags/" rel="section"><i class="menu-item-icon fa fa-fw fa-tags"></i> <br>标签</a>

  </li>
      
      
      
        
        <li class="menu-item menu-item-categories">
      
    

    <a href="/sunpages/categories/" rel="section"><i class="menu-item-icon fa fa-fw fa-th"></i> <br>分类</a>

  </li>
      
      
      
        
        <li class="menu-item menu-item-archives">
      
    

    <a href="/sunpages/archives/" rel="section"><i class="menu-item-icon fa fa-fw fa-archive"></i> <br>归档</a>

  </li>
      
      
      
        
        <li class="menu-item menu-item-photos">
      
    

    <a href="/sunpages/photo/" rel="section"><i class="menu-item-icon fa fa-fw fa-image"></i> <br>Photos</a>

  </li>
      <li class="menu-item menu-item-search">
        <a href="javascript:;" class="popup-trigger">
        
          <i class="menu-item-icon fa fa-search fa-fw"></i> <br>搜索</a>
      </li>
    
  </ul>

</nav>
  <div class="site-search">
    <div class="popup search-popup">
    <div class="search-header">
  <span class="search-icon">
    <i class="fa fa-search"></i>
  </span>
  <div class="search-input" id="search-input"></div>
  <span class="popup-btn-close">
    <i class="fa fa-times-circle"></i>
  </span>
</div>
<div class="algolia-results">
  <div id="algolia-stats"></div>
  <div id="algolia-hits"></div>
  <div id="algolia-pagination" class="algolia-pagination"></div>
</div>

  
</div>
<div class="search-pop-overlay"></div>

  </div>
</div>
    </header>

    
  <div class="back-to-top">
    <i class="fa fa-arrow-up"></i>
    <span>0%</span>
  </div>

  <a href="https://github.com/sunhanwu" class="github-corner" title="Follow me on GitHub" aria-label="Follow me on GitHub" rel="noopener" target="_blank"><svg width="80" height="80" viewBox="0 0 250 250" aria-hidden="true"><path d="M0,0 L115,115 L130,115 L142,142 L250,250 L250,0 Z"></path><path d="M128.3,109.0 C113.8,99.7 119.0,89.6 119.0,89.6 C122.0,82.7 120.5,78.6 120.5,78.6 C119.2,72.0 123.4,76.3 123.4,76.3 C127.3,80.9 125.5,87.3 125.5,87.3 C122.9,97.6 130.6,101.9 134.4,103.2" fill="currentColor" style="transform-origin: 130px 106px;" class="octo-arm"></path><path d="M115.0,115.0 C114.9,115.1 118.7,116.5 119.8,115.4 L133.7,101.6 C136.9,99.2 139.9,98.4 142.2,98.6 C133.8,88.0 127.5,74.4 143.8,58.0 C148.5,53.4 154.0,51.2 159.7,51.0 C160.3,49.4 163.2,43.6 171.4,40.1 C171.4,40.1 176.1,42.5 178.8,56.2 C183.1,58.6 187.2,61.8 190.9,65.4 C194.5,69.0 197.7,73.2 200.1,77.6 C213.8,80.2 216.3,84.9 216.3,84.9 C212.7,93.1 206.9,96.0 205.4,96.6 C205.1,102.4 203.0,107.8 198.3,112.5 C181.9,128.9 168.3,122.5 157.7,114.1 C157.9,116.9 156.7,120.9 152.7,124.9 L141.0,136.5 C139.8,137.7 141.6,141.9 141.8,141.8 Z" fill="currentColor" class="octo-body"></path></svg></a>


    <main id="main" class="main">
      <div class="main-inner">
        <div class="content-wrap">
            

          <div id="content" class="content">
            

  <div id="posts" class="posts-expand">
      <article itemscope itemtype="http://schema.org/Article">
  
  
  
  <div class="post-block post">
    <link itemprop="mainEntityOfPage" href="https://yuandaima1.gitee.io/sunpages/sunpages/2019/03/11/lab2/">

    <span hidden itemprop="author" itemscope itemtype="http://schema.org/Person">
      <meta itemprop="name" content="sunhanwu">
      <meta itemprop="description" content="Talk is cheap, show me the code!">
      <meta itemprop="image" content="http://ipic-picgo.oss-cn-beijing.aliyuncs.com/2019-09-12-logo.jpg">
    </span>

    <span hidden itemprop="publisher" itemscope itemtype="http://schema.org/Organization">
      <meta itemprop="name" content="SunPages">
    </span>
      <header class="post-header">
        <h2 class="post-title" itemprop="name headline">进程实验

          
        </h2>

        <div class="post-meta">
            <span class="post-meta-item">
              <span class="post-meta-item-icon">
                <i class="fa fa-calendar-o"></i>
              </span>
              <span class="post-meta-item-text">发表于</span>

              
                
              

              <time title="创建时间：2019-03-11 20:10:33" itemprop="dateCreated datePublished" datetime="2019-03-11T20:10:33+08:00">2019-03-11</time>
            </span>
          
            

            
              <span class="post-meta-item">
                <span class="post-meta-item-icon">
                  <i class="fa fa-calendar-check-o"></i>
                </span>
                <span class="post-meta-item-text">更新于</span>
                <time title="修改时间：2019-09-12 17:35:49" itemprop="dateModified" datetime="2019-09-12T17:35:49+08:00">2019-09-12</time>
              </span>
            
          
            <span class="post-meta-item">
              <span class="post-meta-item-icon">
                <i class="fa fa-folder-o"></i>
              </span>
              <span class="post-meta-item-text">分类于</span>
              
                <span itemprop="about" itemscope itemtype="http://schema.org/Thing"><a href="/sunpages/categories/%E6%93%8D%E4%BD%9C%E7%B3%BB%E7%BB%9F%E5%AE%9E%E9%AA%8C/" itemprop="url" rel="index"><span itemprop="name">操作系统实验</span></a></span>

                
                
              
            </span>
          

          
  
  <span class="post-meta-item">
    
      <span class="post-meta-item-icon">
        <i class="fa fa-comment-o"></i>
      </span>
        
      
      <span class="post-meta-item-text">Valine：</span>
    
    <a title="valine" href="/sunpages/2019/03/11/lab2/#comments" itemprop="discussionUrl"><span class="post-comments-count valine-comment-count" data-xid="/sunpages/2019/03/11/lab2/" itemprop="commentCount"></span></a>
  </span>
  
  
          <br>
            <span class="post-meta-item" title="本文字数">
              <span class="post-meta-item-icon">
                <i class="fa fa-file-word-o"></i>
              </span>
              
                <span class="post-meta-item-text">本文字数：</span>
              
              <span>3.9k</span>
            </span>
          
            <span class="post-meta-item" title="阅读时长">
              <span class="post-meta-item-icon">
                <i class="fa fa-clock-o"></i>
              </span>
              
                <span class="post-meta-item-text">阅读时长 &asymp;</span>
              
              <span>4 分钟</span>
            </span>
          

        </div>
      </header>

    
    
    
    <div class="post-body" itemprop="articleBody">

      
        <h1 id="实验二实验报告"><a href="#实验二实验报告" class="headerlink" title="实验二实验报告"></a>实验二实验报告</h1><blockquote>
<p>孙汉武    16281047    安全1601</p>
</blockquote><a id="more"></a>
<h2 id="Task-1"><a href="#Task-1" class="headerlink" title="Task 1"></a>Task 1</h2><h3 id="1-1-实验步骤"><a href="#1-1-实验步骤" class="headerlink" title="1.1 实验步骤"></a>1.1 实验步骤</h3><ol>
<li><p>打开一个vi进程</p>
</li>
<li><p>通过ps命令找到名字为vi的进程，命令如下</p>
<figure class="highlight shell"><table><tr><td class="gutter"><pre><span class="line">1</span><br></pre></td><td class="code"><pre><span class="line">ps -auxc | grep vi$</span><br></pre></td></tr></table></figure>
<p><img src="http://ipic-picgo.oss-cn-beijing.aliyuncs.com/2019-04-29-171938.jpg" width="600"></p>
<p>这里对该命令中的参数做出解释</p>
<ul>
<li><code>-aux</code>:    显示所有进程</li>
<li><code>-c</code>:            将command列输出更改为可执行文件名而不是命令名称</li>
<li><code>grep</code>         正则表达式搜索</li>
<li><code>vi$</code>           匹配结尾为vi字符串    </li>
</ul>
<p>这里对ps命令的输出结果每一列的含义做出解释，<code>ps -aux</code>命令的输出结果一共有十一列，从左往右分别是：</p>
</li>
</ol>
<div class="table-container">
<table>
<thead>
<tr>
<th>列名</th>
<th>USER</th>
<th>PID</th>
<th>%CPU</th>
<th>%MEM</th>
<th>VSZ</th>
<th>RSS</th>
</tr>
</thead>
<tbody>
<tr>
<td>含义</td>
<td>进程所属用户名</td>
<td>进程ID</td>
<td>占用CPU百分比</td>
<td>占用内存百分比</td>
<td>虚拟大小</td>
<td>驻留中页的数量</td>
</tr>
<tr>
<td>示例</td>
<td>ubuntu</td>
<td>13716</td>
<td>0.0</td>
<td>0.5</td>
<td>40384</td>
<td>10144</td>
</tr>
</tbody>
</table>
</div>
<div class="table-container">
<table>
<thead>
<tr>
<th>列名</th>
<th>TTY</th>
<th>STAT</th>
<th>START</th>
<th>TIME</th>
<th></th>
</tr>
</thead>
<tbody>
<tr>
<td>含义</td>
<td>终端ID</td>
<td>进程状态</td>
<td>开始时间</td>
<td>累计CPU时间</td>
<td></td>
</tr>
<tr>
<td>实例</td>
<td>pts/2</td>
<td>S+</td>
<td>20:33</td>
<td>0:00</td>
</tr>
</tbody>
</table>
</div>
<ol>
<li><p>寻找vi的父进程，直到init进程为止</p>
<p>使用如下命令查看指定进程的父进程的PID：</p>
<figure class="highlight shell"><table><tr><td class="gutter"><pre><span class="line">1</span><br></pre></td><td class="code"><pre><span class="line">ps -eo pid,ppid,user,command | grep -w ^.&lt;pid&gt;</span><br></pre></td></tr></table></figure>
<blockquote>
<p>说明：</p>
<ol>
<li><code>-eo</code>    表示按照指定格式输出，这里指定的格式是pid,ppid,user,command</li>
<li>\<pid\>     是要查询的pid号</pid\></li>
</ol>
</blockquote>
<p>\<pid\>填写查询进程的pid.</pid\></p>
<ul>
<li><p>通过步骤2可知vi的pid为13716，所以查询vi的父进程</p>
<figure class="highlight shell"><table><tr><td class="gutter"><pre><span class="line">1</span><br></pre></td><td class="code"><pre><span class="line">ps -eo pid,ppid,user,command | grep -w 13716</span><br></pre></td></tr></table></figure>
<p><img src="http://ipic-picgo.oss-cn-beijing.aliyuncs.com/2019-04-29-171945.jpg" width="600"></p>
<p>由图可知，vi的父进程的pid是7854</p>
</li>
<li><p>查询7854的父进程</p>
<figure class="highlight shell"><table><tr><td class="gutter"><pre><span class="line">1</span><br></pre></td><td class="code"><pre><span class="line">ps -eo pid,ppid,user,command | grep -w ^.7854</span><br></pre></td></tr></table></figure>
<p><img src="http://ipic-picgo.oss-cn-beijing.aliyuncs.com/2019-04-29-171948.jpg" width="600"></p>
<p>由图可知，7854的父进程的pid是7745</p>
</li>
<li><p>查询7745的父进程</p>
<figure class="highlight shell"><table><tr><td class="gutter"><pre><span class="line">1</span><br></pre></td><td class="code"><pre><span class="line">ps -eo pid,ppid,user,command | grep -w ^.7745</span><br></pre></td></tr></table></figure>
<p><img src="http://ipic-picgo.oss-cn-beijing.aliyuncs.com/2019-04-29-171955.jpg" width="600"></p>
<p>由图可知，7745的父进程的pid是1</p>
</li>
<li><p>查询1的父进程</p>
<figure class="highlight plain"><table><tr><td class="gutter"><pre><span class="line">1</span><br></pre></td><td class="code"><pre><span class="line">ps -eo pid,ppid,user,command | grep -w 1</span><br></pre></td></tr></table></figure>
<p><img src="http://ipic-picgo.oss-cn-beijing.aliyuncs.com/2019-04-29-171958.jpg" width="600"></p>
</li>
</ul>
<p>综上所述，可以得到如下结果：</p>
<p>| 进程号 | 父进程号 | 所属用户 | 命令 |<br>| ——— | ———— | ———— | —— |<br>| 13716  | 7854     | ubuntu   | vi   |<br>| 7854   | 7745     | ubuntu   | -zsh |<br>| 7745   | 1        | ubuntu   | tmux |<br>| 1      | 0        | root     | init |</p>
<ol>
<li>将步骤三得到的进程树和pstree得到的进程树比较</li>
</ol>
<p>通过<code>pstree</code>命令得到如下结果：</p>
<p><img src="http://ipic-picgo.oss-cn-beijing.aliyuncs.com/2019-04-29-172002.jpg" width="600"></p>
<p>左边的虚线代表init进程，可以看到两种方式得到的进程树是相同的。</p>
<p>两种方式各自的优点如下：</p>
<ul>
<li><code>pstree</code>:<ul>
<li>进程树比较直观，一目了然</li>
<li>能一次显示所有的进程的进程树</li>
</ul>
</li>
<li><code>ps</code>命令查询出的进程树<ul>
<li>能查看每个中间进程的详细信息</li>
<li>ps命令自主性比较好，可以由用户自定义参数</li>
</ul>
</li>
</ul>
</li>
</ol>
<h2 id="Task-2"><a href="#Task-2" class="headerlink" title="Task 2"></a>Task 2</h2><h3 id="2-1-实验步骤"><a href="#2-1-实验步骤" class="headerlink" title="2.1 实验步骤"></a>2.1 实验步骤</h3><ul>
<li>实验代码如下：</li>
</ul>
<p><img src="https://ws2.sinaimg.cn/large/006tKfTcly1g1a82h4avqj31370u0436.jpg" width="600"></p>
<ul>
<li><p>编译并运行程序</p>
<p><img src="http://ipic-picgo.oss-cn-beijing.aliyuncs.com/2019-04-29-172008.jpg" width="600"></p>
<p><img src="http://ipic-picgo.oss-cn-beijing.aliyuncs.com/2019-04-29-172011.jpg" width="600"></p>
</li>
<li><p>查看vi进程和父进程的状态</p>
<ul>
<li>vi进程</li>
</ul>
<p><img src="http://ipic-picgo.oss-cn-beijing.aliyuncs.com/2019-04-29-172015.jpg" width="600"></p>
<p><img src="http://ipic-picgo.oss-cn-beijing.aliyuncs.com/2019-04-29-172020.jpg" width="600"></p>
<p>​    可以看到vi进程的进程号为12703,父进程pid为12702，占用CPU和MEM分别为0.5%和0.6%</p>
<ul>
<li><p>vi进程父进程</p>
<p><img src="http://ipic-picgo.oss-cn-beijing.aliyuncs.com/2019-04-29-172027.jpg" width="600"></p>
</li>
</ul>
</li>
<li><p>对所有进程按照CPU占用率排序</p>
<ul>
<li><p>方法一：使用htop命令，自动按照CPU占用率对进程排序</p>
<p><img src="http://ipic-picgo.oss-cn-beijing.aliyuncs.com/2019-04-29-172032.jpg" width="600"></p>
</li>
<li><p>方法二：使用top命令按照CPU占用率对进程排序</p>
<p>​        <img src="http://ipic-picgo.oss-cn-beijing.aliyuncs.com/2019-04-29-172037.jpg" width="600"></p>
<p>​        </p>
</li>
</ul>
</li>
</ul>
<h2 id="Task-3"><a href="#Task-3" class="headerlink" title="Task 3"></a>Task 3</h2><h3 id="2-1-实验步骤-1"><a href="#2-1-实验步骤-1" class="headerlink" title="2.1 实验步骤"></a>2.1 实验步骤</h3><ol>
<li><p>实验源码</p>
<p><img src="https://ws4.sinaimg.cn/large/006tKfTcly1g1a83mqnwoj30uk0u0gr4.jpg" width="600">    </p>
<p>对上述源码的分析包含以下几个方面：</p>
<ul>
<li>fork函数的功能和返回值：<ul>
<li>fork的功能是从当前行开始复制父进程，创建一个和父进程一样的子进程</li>
<li>fork的返回值在父进程中大于0，在子进程中等于0，如果创建子进程发生错误返回-1</li>
</ul>
</li>
<li>程序流程如下：</li>
</ul>
<p><img src="http://ipic-picgo.oss-cn-beijing.aliyuncs.com/2019-04-29-172042.jpg" width="600"></p>
<ul>
<li><p>程序解释：</p>
<p>结合上面的程序流程图，可以看到程序执行最初的那个进程就是父进程A，在一开始就通过fork函数创建一个子进程B，并用p1接受fork的返回值，由于p1在进程A和进程B的值不同，所以两个进程接下来执行的代码部分并不相同。进程A执行p1&gt;0的部分代码，并且在p1&gt;0的那部分代码中，进程A再次通过fork创建了一个子进程C。随后进程A和进程C分别打印自己的pid和ppid(父进程id)。在来看进程B，在p1==0的那部分代码中，进程B也是通过fork创建了一个子进程D,并将fork的返回值交给p2，在父进程B中，p2的值大于0，所以父进程B还创建了一个子进程E,而在子进程D中，p2\=\=0，所以不执行p2&gt;0代码块里面的语句，直接打印pid和ppid，之后分别是进程E和B打印pid和ppid。到此满足实验要求的进程树创建完毕。</p>
</li>
</ul>
</li>
<li><p>编译执行</p>
<figure class="highlight shell"><table><tr><td class="gutter"><pre><span class="line">1</span><br></pre></td><td class="code"><pre><span class="line">gcc task3.c -o task3</span><br></pre></td></tr></table></figure>
<p><img src="http://ipic-picgo.oss-cn-beijing.aliyuncs.com/2019-04-29-172048.jpg" width="600"></p>
</li>
<li><p>调试分析</p>
<p>由于涉及的进程数比较多，所以通过调试的方式分析比较直观，所以下面利用gdb调试器进行调试。</p>
<p>首先是调试前的准备,在gcc编译的时候加上-g 参数以支持gdb调试:</p>
<figure class="highlight shell"><table><tr><td class="gutter"><pre><span class="line">1</span><br></pre></td><td class="code"><pre><span class="line">gcc -g task3.c -o task3</span><br></pre></td></tr></table></figure>
<p>通过<code>gdb task3</code>命令进入调试器，首先是配置成多进程调试模式：</p>
<figure class="highlight shell"><table><tr><td class="gutter"><pre><span class="line">1</span><br><span class="line">2</span><br><span class="line">3</span><br></pre></td><td class="code"><pre><span class="line"><span class="meta">#</span><span class="bash"> 在gdb中按照如下命令设置，可以设置成对进城调试模式</span></span><br><span class="line">set follow-fork-mode parent</span><br><span class="line">set detach-on-fork off</span><br></pre></td></tr></table></figure>
<p><img src="http://ipic-picgo.oss-cn-beijing.aliyuncs.com/2019-04-29-172052.jpg" width="600"></p>
<p>设置断点，在含有fork函数的所有地方设置断点</p>
<p><img src="http://ipic-picgo.oss-cn-beijing.aliyuncs.com/2019-04-29-172056.jpg" width="600"></p>
<p>开始调试，首先通过<code>r</code>命令进入第一个进程开始调试，这里称此进程为A :</p>
<p><img src="http://ipic-picgo.oss-cn-beijing.aliyuncs.com/2019-04-29-172100.jpg" width="600"></p>
<p>通过调试结果可以看出来进程A的进程号是28608，进程A的父进程pid是28570，并且p1=28613大于0，说明进程A走的是<code>if (p1&gt;0)</code>下面的那个分支。</p>
<p>分析源码可知，进程A在第6行和第7行分别创建了一个子进程，我分别称之为进程B和进程C.</p>
<p><img src="http://ipic-picgo.oss-cn-beijing.aliyuncs.com/2019-04-29-172113.jpg" width="600"></p>
<p>下面切换到进程B中调试：</p>
<p><img src="http://ipic-picgo.oss-cn-beijing.aliyuncs.com/2019-04-29-172117.jpg" width="600"></p>
<p>通过输出的调试信息可以看出，此时的p1的值为0，说明进程B执行的是<code>P1==0</code>下面的代码,而<code>P2&gt;0</code>说明此时进程B执行了<code>if (p2&gt;0)</code>后面的fork函数。最后得到进程B的pid为28613，进程B的父进程是进程A，其pid是28608，这与上面的进程A的pid是一直的。</p>
<p>在调试信息中可以看到，当进程B运行到13行和15行的时候分别创建了两个新的子进程，我们称这两个进程为进程D和进程E</p>
<p><img src="http://ipic-picgo.oss-cn-beijing.aliyuncs.com/2019-04-29-172121.jpg" width="600"></p>
<p>接着对进程C进程分析，进程C是进程A在26行复制得到，并且后面没有创建任何其他的子进程。</p>
<p><img src="http://ipic-picgo.oss-cn-beijing.aliyuncs.com/2019-04-29-172123.jpg" width="600"></p>
</li>
</ol>
<p>​    通过调试信息可以看出，进程C的pid为28615，其父进程pid为28606,父进程为A，这与上面的信息一致。</p>
<p>​    再对进程D进程分析：</p>
<p><img src="http://ipic-picgo.oss-cn-beijing.aliyuncs.com/2019-04-29-172128.jpg" width="600"></p>
<p>​    通过上面分析可知，p1和p2均为0,所以说明进程D是进程B在13行创建的子进程，进程D的spid为28740，其父进程pid为28613，和前面的信息一致。</p>
<p>​    最后分析进程E：</p>
<p><img src="http://ipic-picgo.oss-cn-beijing.aliyuncs.com/2019-04-29-172131.jpg" width="600"></p>
<p>​    通过输出的信息可以看到p1=0,p2&gt;0，分析可知进程E是进程B在15行创建的子进程。进程E的pid是28741，其父进程pid是28613,恰好是进程B的pid</p>
<p>​    分析上面可知，在本次调试过程中，得到的进程信息如下所示：</p>
<div class="table-container">
<table>
<thead>
<tr>
<th style="text-align:center">进程</th>
<th style="text-align:center">A</th>
<th style="text-align:center">B</th>
<th style="text-align:center">C</th>
<th style="text-align:center">D</th>
<th style="text-align:center">E</th>
</tr>
</thead>
<tbody>
<tr>
<td style="text-align:center">pid</td>
<td style="text-align:center">28608</td>
<td style="text-align:center">28613</td>
<td style="text-align:center">28615</td>
<td style="text-align:center">28740</td>
<td style="text-align:center">28741</td>
</tr>
<tr>
<td style="text-align:center">ppid</td>
<td style="text-align:center">28570</td>
<td style="text-align:center">28608</td>
<td style="text-align:center">28608</td>
<td style="text-align:center">28613</td>
<td style="text-align:center">28613</td>
</tr>
</tbody>
</table>
</div>
<p>​    于是可以得到这五个进程的进程树如下(与实验要求一致)：</p>
<p><img src="http://ipic-picgo.oss-cn-beijing.aliyuncs.com/2019-04-29-172138.jpg" width="500">        </p>
<ol>
<li><p>遇到的问题及解决办法</p>
<ul>
<li><p>问题</p>
<p>刚开始的时候由于没有考虑到父进程会在子进程之前结束的问题，导致所有的子进程在getppid()的时候父进程已经结束了，得到的是init进程的pid=1，所以在代码中加入sleep(1)，让父进程等待一秒钟再结束，等待子进程获取了其pid。</p>
<p><img src="http://ipic-picgo.oss-cn-beijing.aliyuncs.com/2019-04-29-172141.jpg" width="600"></p>
</li>
<li><p>解决办法</p>
<p>在代码中中加入sleep(1),再次编译执行即可得到正确结果。</p>
</li>
</ul>
</li>
</ol>
<h2 id="Task4"><a href="#Task4" class="headerlink" title="Task4"></a>Task4</h2><ol>
<li><p>实验源码</p>
<p><img src="https://ws1.sinaimg.cn/large/006tKfTcly1g1a85bo9v3j316u06y3z9.jpg" width="600"></p>
<p>代码和Task3中的代码基本一致，只是将输出信息编程循环输出，并且没打印一次后sleep一秒钟</p>
</li>
<li><p>打印进程树</p>
<p><img src="http://ipic-picgo.oss-cn-beijing.aliyuncs.com/2019-04-29-172147.jpg" width="600"></p>
<p>可以看到进程树信息如上图所示</p>
</li>
<li><p>终止进程p2</p>
<ul>
<li><p>采用<code>kill -9</code>的方式终止进程p2</p>
<p>删除之p2的子进程p4和p5挂载init上面。然后进程p1,p2,p3还是原来的进程，进程p2虽然被杀死，但是变成Z+的状态，成为退出状态进程的僵尸进程。</p>
<p><img src="http://ipic-picgo.oss-cn-beijing.aliyuncs.com/2019-04-29-172148.jpg" width="600"></p>
<p><img src="http://ipic-picgo.oss-cn-beijing.aliyuncs.com/2019-04-29-172155.jpg" width="600"></p>
<p><img src="http://ipic-picgo.oss-cn-beijing.aliyuncs.com/2019-04-29-172151.jpg" width="600"></p>
<p>查看输出信息，发现进程p2的输出已经没有了</p>
<p><img src="http://ipic-picgo.oss-cn-beijing.aliyuncs.com/2019-04-29-172158.jpg" width="600"></p>
</li>
<li><p>采用<code>exit()</code>正常退出进程</p>
<ul>
<li><p>实验源码如下：</p>
<p><img src="https://ws1.sinaimg.cn/large/006tKfTcly1g1a85yjcijj313e0lmdi6.jpg" width="600"></p>
</li>
<li><p>实验步骤</p>
<p>下面是进程p2在exit之前的进程树</p>
<p><img src="http://ipic-picgo.oss-cn-beijing.aliyuncs.com/2019-04-29-172202.jpg" width="600"></p>
<p>代码中可以看到，进程p2在输出10次之后就会正常退出。下面是进程p2退出之后的进程树。</p>
<p><img src="http://ipic-picgo.oss-cn-beijing.aliyuncs.com/2019-04-29-172205.jpg" width="600"></p>
<p><img src="http://ipic-picgo.oss-cn-beijing.aliyuncs.com/2019-04-29-172208.jpg" width="600"></p>
<p>再查看进程p2的详细信息，得知进程p2的状态也变成了Z+，成为即将退出的僵尸进程。</p>
<p><img src="http://ipic-picgo.oss-cn-beijing.aliyuncs.com/2019-04-29-172212.jpg" width="600"></p>
</li>
</ul>
</li>
</ul>
</li>
</ol>
<ul>
<li><p>采用段错误退出</p>
<ul>
<li><p>实验代码</p>
<p><img src="https://ws4.sinaimg.cn/large/006tKfTcly1g1a86kbwu9j313g0patbj.jpg" width="600"></p>
<p>实验代码如上，在进程p2的进程段里面定义一个野指针，野指针没有初始化会产生段错误导致进程退出。</p>
</li>
<li><p>实验步骤</p>
<p>下面是进程p2在退出之前的的进程树</p>
</li>
</ul>
<p><img src="http://ipic-picgo.oss-cn-beijing.aliyuncs.com/2019-04-29-172216.jpg" width="600"></p>
<p>​    下面在p2进程退出之后的进程出，进程p2的子进程p4,p5挂载在init上，然后p2进程变成了状态为Z+ 的僵尸进程。</p>
<p><img src="http://ipic-picgo.oss-cn-beijing.aliyuncs.com/2019-04-29-172220.jpg" width="600"></p>
<p><img src="http://ipic-picgo.oss-cn-beijing.aliyuncs.com/2019-04-29-172223.jpg" width="600"></p>
<p><img src="http://ipic-picgo.oss-cn-beijing.aliyuncs.com/2019-04-29-172226.jpg" width="600"></p>
<p>综上所述，三种方式的终止进程都会将进程变成僵尸进程，进程在退出的过程中，系统回收资源，除了task_struct结构（以及少数资源）以外。于是进程就只剩下task_struct这么个空壳，故称为僵尸。之所以保留task_struct，是因为task_struct里面保存了进程的退出码、以及一些统计信息。而其父进程很可能会关心这些信息。这也是为什么进程p2终止之后在进程树中还能看到进程p2的信息等。</p>
</li>
</ul>

    </div>

    
    
    
        
      
        <div id="reward-container">
  <div></div>
  <button id="reward-button" disable="enable" onclick="var qr = document.getElementById(&quot;qr&quot;); qr.style.display = (qr.style.display === 'none') ? 'block' : 'none';">
    打赏
  </button>
  <div id="qr" style="display: none;">
        
      
      <div style="display: inline-block">
        <img src="https://ipic-picgo.oss-cn-beijing.aliyuncs.com/20200705000845.png" alt="sunhanwu 支付宝">
        <p>支付宝</p>
      </div>

  </div>
</div>

      

      <footer class="post-footer">
          
            
          
          <div class="post-tags">
            
              <a href="/sunpages/tags/%E6%93%8D%E4%BD%9C%E7%B3%BB%E7%BB%9F/" rel="tag"># 操作系统</a>
            
          </div>
        

        

          <div class="post-nav">
            <div class="post-nav-next post-nav-item">
              
                <a href="/sunpages/2019/03/01/gitbook/" rel="next" title="在github部署gitbook教程">
                  <i class="fa fa-chevron-left"></i> 在github部署gitbook教程
                </a>
              
            </div>

            <span class="post-nav-divider"></span>

            <div class="post-nav-prev post-nav-item">
              
                <a href="/sunpages/2019/03/21/lab3/" rel="prev" title="进程实验二">
                  进程实验二 <i class="fa fa-chevron-right"></i>
                </a>
              
            </div>
          </div>
        
      </footer>
    
  </div>
  
  
  
  </article>

  </div>


          </div>
          
    
    <div class="comments" id="comments"></div>
  

        </div>
          
  
  <div class="sidebar-toggle">
    <div class="sidebar-toggle-line-wrap">
      <span class="sidebar-toggle-line sidebar-toggle-line-first"></span>
      <span class="sidebar-toggle-line sidebar-toggle-line-middle"></span>
      <span class="sidebar-toggle-line sidebar-toggle-line-last"></span>
    </div>
  </div>

  <aside class="sidebar">
    <div class="sidebar-inner">
        
        
        
        
      

      <ul class="sidebar-nav motion-element">
        <li class="sidebar-nav-toc">
          文章目录
        </li>
        <li class="sidebar-nav-overview">
          站点概览
        </li>
      </ul>

      <!--noindex-->
      <div class="post-toc-wrap sidebar-panel">
          <div class="post-toc motion-element"><ol class="nav"><li class="nav-item nav-level-1"><a class="nav-link" href="#实验二实验报告"><span class="nav-number">1.</span> <span class="nav-text">实验二实验报告</span></a><ol class="nav-child"><li class="nav-item nav-level-2"><a class="nav-link" href="#Task-1"><span class="nav-number">1.1.</span> <span class="nav-text">Task 1</span></a><ol class="nav-child"><li class="nav-item nav-level-3"><a class="nav-link" href="#1-1-实验步骤"><span class="nav-number">1.1.1.</span> <span class="nav-text">1.1 实验步骤</span></a></li></ol></li><li class="nav-item nav-level-2"><a class="nav-link" href="#Task-2"><span class="nav-number">1.2.</span> <span class="nav-text">Task 2</span></a><ol class="nav-child"><li class="nav-item nav-level-3"><a class="nav-link" href="#2-1-实验步骤"><span class="nav-number">1.2.1.</span> <span class="nav-text">2.1 实验步骤</span></a></li></ol></li><li class="nav-item nav-level-2"><a class="nav-link" href="#Task-3"><span class="nav-number">1.3.</span> <span class="nav-text">Task 3</span></a><ol class="nav-child"><li class="nav-item nav-level-3"><a class="nav-link" href="#2-1-实验步骤-1"><span class="nav-number">1.3.1.</span> <span class="nav-text">2.1 实验步骤</span></a></li></ol></li><li class="nav-item nav-level-2"><a class="nav-link" href="#Task4"><span class="nav-number">1.4.</span> <span class="nav-text">Task4</span></a></li></ol></li></ol></div>
        
      </div>
      <!--/noindex-->

      <div class="site-overview-wrap sidebar-panel">
        <div class="site-author motion-element" itemprop="author" itemscope itemtype="http://schema.org/Person">
    <img class="site-author-image" itemprop="image"
      src="http://ipic-picgo.oss-cn-beijing.aliyuncs.com/2019-09-12-logo.jpg"
      alt="sunhanwu">
  <p class="site-author-name" itemprop="name">sunhanwu</p>
  <div class="site-description" itemprop="description">Talk is cheap, show me the code!</div>
</div>
  <nav class="site-state motion-element">
      <div class="site-state-item site-state-posts">
        
          <a href="/sunpages/archives/%20%7C%7C%20archive">
        
          <span class="site-state-item-count">29</span>
          <span class="site-state-item-name">博客</span>
        </a>
      </div>
    
      
      
      <div class="site-state-item site-state-categories">
        
          
            <a href="/sunpages/categories/%20%7C%7C%20th">
          
        
        <span class="site-state-item-count">7</span>
        <span class="site-state-item-name">分类</span>
        </a>
      </div>
    
      
      
      <div class="site-state-item site-state-tags">
        
          
            <a href="/sunpages/tags/%20%7C%7C%20tags">
          
        
        <span class="site-state-item-count">18</span>
        <span class="site-state-item-name">标签</span>
        </a>
      </div>
    
  </nav>
  <div class="links-of-author motion-element">
      <span class="links-of-author-item">
      
      
        
      
      
        
      
        <a href="https://github.com/sunhanwu" title="GitHub &rarr; https://github.com/sunhanwu" rel="noopener" target="_blank"><i class="fa fa-fw fa-github"></i>GitHub</a>
      </span>
    
      <span class="links-of-author-item">
      
      
        
      
      
        
      
        <a href="mailto:1965190613@qq.com" title="E-Mail &rarr; mailto:1965190613@qq.com" rel="noopener" target="_blank"><i class="fa fa-fw fa-envelope"></i>E-Mail</a>
      </span>
    
  </div>


  <div class="links-of-blogroll motion-element">
    <div class="links-of-blogroll-title">
      <i class="fa fa-fw fa-link"></i>
      Links
    </div>
    <ul class="links-of-blogroll-list">
        <li class="links-of-blogroll-item">
          <a href="https://jackyanghc.github.io/" title="https://jackyanghc.github.io/" rel="noopener" target="_blank">Jackyanghc</a>
        </li>
      
        <li class="links-of-blogroll-item">
          <a href="https://michel-liu.github.io/" title="https://michel-liu.github.io/" rel="noopener" target="_blank">Michel</a>
        </li>
      
        <li class="links-of-blogroll-item">
          <a href="https://www.cnblogs.com/morwing/" title="https://www.cnblogs.com/morwing/" rel="noopener" target="_blank">morwing</a>
        </li>
      
    </ul>
  </div>

      </div>

    </div>
  </aside>
  <div id="sidebar-dimmer"></div>


      </div>
    </main>

    <footer id="footer" class="footer">
      <div class="footer-inner">
        <div class="copyright">&copy; <span itemprop="copyrightYear">2020</span>
  <span class="with-love" id="animate">
    <i class="fa fa-user"></i>
  </span>
  <span class="author" itemprop="copyrightHolder">sunhanwu</span>
    <span class="post-meta-divider">|</span>
    <span class="post-meta-item-icon">
      <i class="fa fa-area-chart"></i>
    </span>
      <span class="post-meta-item-text">站点总字数：</span>
    
    <span title="站点总字数">161k</span>
    <span class="post-meta-divider">|</span>
    <span class="post-meta-item-icon">
      <i class="fa fa-coffee"></i>
    </span>
      <span class="post-meta-item-text">站点阅读时长 &asymp;</span>
    
    <span title="站点阅读时长">2:26</span>
</div>
  <div class="theme-info">主题 – <a href="https://theme-next.org" class="theme-link" rel="noopener" target="_blank">NexT.Pisces</a> v7.4.0</div>

        












        
      </div>
    </footer>
  </div>

  


  <script src="/sunpages/lib/anime.min.js?v=3.1.0"></script>
  <script src="/sunpages/lib/velocity/velocity.min.js?v=1.2.1"></script>
  <script src="/sunpages/lib/velocity/velocity.ui.min.js?v=1.2.1"></script>

<script src="/sunpages/js/utils.js?v=7.4.0.js"></script>

<script src="/sunpages/js/motion.js?v=7.4.0.js"></script>


<script src="/sunpages/js/schemes/pisces.js?v=7.4.0.js"></script>


<script src="/sunpages/js/next-boot.js?v=7.4.0.js"></script>




  
  <script>
    (function(){
      var bp = document.createElement('script');
      var curProtocol = window.location.protocol.split(':')[0];
      bp.src = (curProtocol === 'https') ? 'https://zz.bdstatic.com/linksubmit/push.js' : 'http://push.zhanzhang.baidu.com/push.js';
      var s = document.getElementsByTagName("script")[0];
      s.parentNode.insertBefore(bp, s);
    })();
  </script>








  
<link rel="stylesheet" href="//cdn.jsdelivr.net/npm/instantsearch.js@2/dist/instantsearch.min.css">
<script src="//cdn.jsdelivr.net/npm/instantsearch.js@2/dist/instantsearch.min.js"></script>
<script src="/sunpages/js/algolia-search.js?v=7.4.0.js"></script>
















  

  

  

  


<script>
NexT.utils.getScript('//unpkg.com/valine/dist/Valine.min.js', () => {
  var GUEST = ['nick', 'mail', 'link'];
  var guest = 'nick,mail,link';
  guest = guest.split(',').filter(item => {
    return GUEST.includes(item);
  });
  new Valine({
    el: '#comments',
    verify: false,
    notify: false,
    appId: 'ToSqcWxrMe4Fx1bTFKjHnFQn-gzGzoHsz',
    appKey: 'WIlMiWIudPsl2Q2PsMVfiUUH',
    placeholder: 'Just go go',
    avatar: 'mm',
    meta: guest,
    pageSize: '10' || 10,
    visitor: false,
    lang: '' || 'zh-cn',
    path: location.pathname
  });
}, window.Valine);
</script><!-- hexo-inject:begin --><!-- Begin: Injected MathJax -->
<script type="text/x-mathjax-config">
  MathJax.Hub.Config("");
</script>

<script type="text/x-mathjax-config">
  MathJax.Hub.Queue(function() {
    var all = MathJax.Hub.getAllJax(), i;
    for(i=0; i < all.length; i += 1) {
      all[i].SourceElement().parentNode.className += ' has-jax';
    }
  });
</script>

<script type="text/javascript" src="">
</script>
<!-- End: Injected MathJax -->
<!-- hexo-inject:end -->

</body>
</html>
